﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace IWMAG.Scripting.Interpreter {
    public class ArrayRunValue : List<RunValue> {
        public ArrayRunValue() {
        }

        public ArrayRunValue(IEnumerable<char> stringtochar) {
            foreach (char c in stringtochar) {
                Add(new RunValue(c.ToString()));
            }
        }

        public ArrayRunValue(IEnumerable cast) {
            foreach (object o in cast) {
                Add(new RunValue(o));
            }
        }

        public new RunValue this[int o] {
            get {
                return base[o];
            }
            set {
                if (o == -1) {
                    Add(value);
                } else if (Count > o) {
                    base[o] = value;
                } else {
                    throw new IndexOutOfRangeException();
                }
            }
        }

        public override string ToString() {
            if (Count == 0) {
                return "{ }";
            }

            string s = "{";
            foreach (RunValue val in this) {
                s += val.ToString() + ", ";
            }
            return s.Substring(0, s.Length - 2) + "}";
        } 
    }
}
